package day4.Exer;

import java.util.Scanner;

public class Market {
    Scanner in = new Scanner(System.in);
    String name, adress;
    String[] membNo = new String[100];
    String[] membName = new String[100];
    String[] membPhone = new String[100];
    int[] membPoint = new int[100];
    Card c;
    int count;

    public boolean addinfo(Card c) {
        for (int i = 0; i < membNo.length; i++) {
            if (membNo[i] == null) {
                membNo[i] = c.cardNo;
                membName[i] = c.name;
                membPhone[i] = c.phone;
                membPoint[i] = c.point;
                count++;
                return true;
            }
        }
        System.out.println("会员信息已满");
        return true;
    }

    public void show() {
        for(int i=0;i<count;i++){
                System.out.println(membNo[i]+"    "+membName[i]+"    "+membPhone[i]+"    "+ membPoint[i]);

        }
    }

    public boolean checkCardNoRepeat(String no) {
        for (int i = 0; i <=count; i++) {
            if (membNo[i].equals(no)) {
                System.out.println("卡号已被使用，请重新添加");
                return true;
            }
            return false;
        }
        return true;
    }

    public boolean inc(String cardNo, int fen) {
        for (int i = 0; i <=count; i++) {
            if (membNo[i].equals(cardNo)) {
                membPoint[i] += fen;
                return true;
            }
            System.out.println(cardNo + "这张会员卡不存在！");
            return false;
        }
        return true;
    }

    public String exchange(String cardNo, int chsoen) {

        switch (chsoen) {
            case 1: {
                for (int i = 0; i <=count; i++) {
                    if (membNo[i].equals(cardNo)) {
                        if (membPoint[i] < 100) {
                            System.out.println("抱歉，您的积分不够！");
                            return null;
                        }
                        membPoint[i] = membPoint[i] - 100;
                        System.out.println("使用100积分兑换餐巾纸一包！");
                        break;
                    }
                    System.out.println("您输入的卡号不存在！");
                    return null;
                }
                break;
            }
            case 2: {
                for (int i = 0; i <=count; i++) {
                    if (membNo[i].equals(cardNo)) {
                        if (membPoint[i] < 400) {
                            System.out.println("抱歉，您的积分不够！");
                            return null;
                        }
                        membPoint[i] = membPoint[i] - 400;
                        System.out.println("使用400积分兑换剃须刀一把！");
                        break;
                    }
                    System.out.println("您输入的卡号不存在！");
                    return null;
                }
                break;
            }
            case 3: {
                for (int i = 0; i <=count; i++) {
                    if (membNo[i].equals(cardNo)) {
                        if (membPoint[i] < 1000) {
                            System.out.println("抱歉，您的积分不够!");
                            return null;
                        }
                        membPoint[i] = membPoint[i] - 1000;
                        System.out.println("使用1000积分兑换超过一个!");
                        break;
                    }
                    System.out.println("您输入的卡号不存在！");
                    return null;
                }
                break;
            }
            default: {
                System.out.println("选择错误，请重新选择");
                break;
            }
        }
        return cardNo;
    }

    public void showcard() {
        c.showcardinfo();
    }

}
